/**
 * 文  件  名：  ThirdAccountDaoProxy.java
 * 工  程  名：  7You
 * 创建日期：  2013-10-13
 * 创建作者：  杨  强
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IThirdAccountDao;
import com.qiyou.dao.impl.ThirdAccountDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.ThirdAccount;
import com.qiyou.entity.UserInfo;
import com.qiyou.util.DBUtil;

/**
 * 三方账号数据操作代理类
 * 
 * @author 杨 强
 * 
 */
public class ThirdAccountDaoProxy implements IThirdAccountDao {
    private Connection conn = null;
    private IThirdAccountDao dao = null;

    public ThirdAccountDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new ThirdAccountDaoImpl(conn);
    }

    @Override
    public boolean doCreate(ThirdAccount thirdAccount) throws SQLException {
        boolean result = false;
        if (null != thirdAccount) {
            try {
                result = dao.doCreate(thirdAccount);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doDelete(ThirdAccount thirdAccount) throws SQLException {
        boolean result = false;
        if (null != thirdAccount) {
            try {
                result = dao.doDelete(thirdAccount);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doUpdate(ThirdAccount thirdAccount) throws SQLException {
        boolean result = false;
        if (null != thirdAccount) {
            try {
                result = dao.doUpdate(thirdAccount);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

    @Override
    public List<ThirdAccount> getThirdAccount(String userID)
            throws SQLException {
        List<ThirdAccount> result = null;
        if ((null != userID) && (!userID.isEmpty())) {
            try {
                result = dao.getThirdAccount(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

    @Override
    public List<UserInfo> getThirdAccount(Object... params) throws SQLException {
        List<UserInfo> result = null;
        if (null != params) {
            try {
                result = dao.getThirdAccount(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

}
